package com.bunnyhsu.controller;

import com.bunnyhsu.dto.Result;
import com.bunnyhsu.enums.FailEnum;
import com.bunnyhsu.model.Admin;
import com.bunnyhsu.service.AdminService;
import com.bunnyhsu.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by xl on 2018/4/12.
 */
@RestController
@CrossOrigin("*")
public class AdminController {
    @Autowired
    private AdminService adminService;

    @PostMapping("/login")
    public Result login(Admin admin)
    {
        Admin tempAdmin = adminService.login(admin.getId(),admin.getPwd());
        if(tempAdmin==null)
        {
            return ResultUtil.fail(FailEnum.LOGIN_FAIL.getId(),FailEnum.LOGIN_FAIL.getMsg());
        }
        else
        {
            return ResultUtil.success(tempAdmin);
        }
    }
}
